def threeSumClosest(nums, target):
    nums.sort()
    len_sums = len(nums)
    min_cha = abs(target) + abs(nums[-1]) * 3
    for i in range(0, len_sums - 2):
        if i != 0 and nums[i] == nums[i - 1]:
            continue
        j, h = i + 1, len_sums - 1
        while j < h:
            num_sum = nums[i] + nums[j] + nums[h]
            if num_sum == target:
                return target
            elif num_sum < target:
                j += 1
            else:
                h -= 1
            if abs(num_sum - target) <= min_cha:
                min_cha = abs(num_sum - target)
                res = num_sum
    return res


print(threeSumClosest([1, 1, 1, 1], -100))
